package com.neusoft.neuiotms.dcom.repository.incident.impl;

import com.neusoft.bizcore.web.jpa.repository.AbstractRepository;
import com.neusoft.neuiotms.dcom.model.incident.IncidentHandle;
import com.neusoft.neuiotms.dcom.model.incident.QIncidentHandle;
import com.neusoft.neuiotms.dcom.repository.incident.CustomizedIncidentHandleRepository;
import com.querydsl.jpa.impl.JPAQuery;

/**
 * @author WYS
 * @date 2020年8月18日 下午2:10:01
 */
public class CustomizedIncidentHandleRepositoryImpl extends AbstractRepository
        implements CustomizedIncidentHandleRepository {

    @Override
    protected Class<?> getModelClass() {
        return IncidentHandle.class;
    }

    @Override
    public IncidentHandle findByWorkNum(final String workOrderNum) {
        final QIncidentHandle qIncidentHandle = QIncidentHandle.incidentHandle;
        final JPAQuery<IncidentHandle> query = this.query().selectFrom(qIncidentHandle);
        query.where(qIncidentHandle.workNum.eq(workOrderNum))
                .orderBy(qIncidentHandle.createTime.desc()).limit(1);
        return query.fetchOne();
    }

}
